package com.sky.controller.user;

import com.sky.entity.Setmeal;
import com.sky.result.Result;
import com.sky.service.DishService;
import com.sky.service.SetmealService;
import com.sky.vo.DishItemVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController("userSetmealController")
@RequestMapping("/user/setmeal")
@Slf4j
@Api(tags = "C端-套餐浏览接口")
public class SetmealController {
    @Autowired
    private SetmealService setmealService;


    @GetMapping("/list")
    @Cacheable(cacheNames = "setmealCache",key = "#categoryId") // 在执行请求前判断缓存中是否存在数据，存在则直接从缓存中取出
    public Result<List<Setmeal>> list(Long categoryId) {        // 否则方法执行结束以后将查出的数据加入redis缓存
        log.info("根据分类id批量查询套餐:{}",categoryId);
        List<Setmeal> list = setmealService.listByCategoryId(categoryId);
        return Result.success(list);
    }
    @GetMapping("/dish/{id}")
    @ApiOperation("根据套餐id查询菜品信息")
    public Result<List<DishItemVO>> getDishesBySetmealId(@PathVariable Long id) {
        log.info("根据套餐id批量查询菜品:{}",id);
        List<DishItemVO> list = setmealService.listWithSetmealDish(id);
        return Result.success(list);
    }
}
